-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: select_dypes impl #7434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: select_dypes impl #7434
Conversation
should not allow |
Yep that's the wip part :) |
I'll just implement on frame directly |
This is a subtle issue. specifying
need some tests with string dtypes too (and invalid ones I think you should raise), e.g. |
I check the dtype.type attribute if it's a subclass of the passed in dtype. All dtypes are converted using np.dtype before any checks occur |
whew jeez there are all sorts of dtype special cases |
@jreback i think |
not sure i see the problem with |
|
||
# empty include/exclude -> defaults to True | ||
wanted = pd.Series(dict.fromkeys(index, not bool(include))) | ||
not_wanted = pd.Series(dict.fromkeys(index, not bool(exclude))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI you can just do pd.Series(not bool(exclude), index)
. (Semantically this one seems strange, I think this is actually not_not_wanted
?? :s )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah the implementation is a bit unreadable right now ... i'm working on it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries. This'll be neat!
hows this coming? |
Will get to it today. Work has picked up in the last week or so, haven't had as much time as I would like for pandas. :( |
@jreback should empty include and empty exclude return an empty frame? |
or how about a raise since that doesn't really make any sense |
oh duh i'm already doing that nevermind |
yeh I think you have to have either include or exclude non empty / not none still could return empty frame of course |
now disallowing |
you could allow thinks like 'datetime', 'date time', datetime.datetime, np.datetime eg generic datetime dtypes (you may need to have a dict/regex matcher for things like this) |
i'm already allowing |
ok cool |
the one thing that's currently not possible is getting columns that are non string object dtypes |
ie if you ask for object you'll always get strings as well as any other objects |
no distinction between string and those anyhow (their could be but not now) |
@@ -1149,11 +1143,97 @@ default value. | |||
s.get('a') # equivalent to s['a'] | |||
s.get('x', default=-1) | |||
|
|||
Selecting columns based on ``dtype`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be here: (the whole section): http://pandas-docs.github.io/pandas-docs-travis/basics.html#dtypes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok will move
@jreback @jorisvandenbossche any more comments? |
@@ -1603,6 +1603,66 @@ def _get_fill_func(method): | |||
#---------------------------------------------------------------------- | |||
# Lots of little utilities | |||
|
|||
def _validate_date_like_dtype(dtype): | |||
try: | |||
typ = np.datetime_data(dtype)[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never knew that was a method like this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah only thing is that the second tuple element is num
which is used only internall in numpy AFAICT, it seems to always be 1 when used in python but i think it's used to do conversions between different units.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can also just test the kind as M right? (
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no i'm checking that the unit is either generic
(this occurs when a user passes in np.datetime64
; 'datetime64[generic]'
shouldn't really be passed in by a user, tho it will work) or ns
, i could write something simple that parses out the unit for us, but not sure that's necessary
I think you just need a couple of doc edits (from above)..... |
Yeah sorry things just picking up a lot at work. Will do this today, so we can get the ball rolling on the release. |
@jreback good 2 go? |
do you test if |
good call, don't think i test thits |
@cpcloud when you have a chance |
@jreback this is good to go i think |
|
||
|
||
|
||
Working with package options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this supposed to be added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crap totally missed that htanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you are not rebased to master?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as soon as you are ready then go ahead and merge (don't worry about travis). it already passed :)
I think this section slipped back in somehow: http://pandas-docs.github.io/pandas-docs-travis/options.html (as the new options section is there) |
hmm. go ahead and merge this. let's fix in another commit (removing the options stuff from basics) https://github.com/pydata/pandas/pull/7578/files |
never mind, master looks fine |
cool merging |
nice ! |
I think you can add a mini example in 0.14.1 for |
you can now update SO with your docs link: http://pandas-docs.github.io/pandas-docs-travis/basics.html#basics-selectdtypes for the gazillion questions that always happen about this :) |
This needs to be tested with dtype "category" #7217 |
makes this work |
closes #7316
examples: